package com.study.d5_thread_exer;

import lombok.Data;

@Data
public class Desk {
    private String data;

    public synchronized void get() throws Exception {
        String name = Thread.currentThread().getName();
        Thread.sleep(500);
        if (data == null) {
            this.notifyAll();
            this.wait();
        } else {
            System.out.println(name + "吃了" + data);
            data = null;
            this.notifyAll();
            this.wait();
        }
    }

    public synchronized void put() throws Exception {
        String name = Thread.currentThread().getName();
        if (data == null) {
            data = name + "做的肉包子";
            System.out.println(name+"做了肉包子");
            this.notifyAll();
            this.wait();
        } else {
            this.notifyAll();
            this.wait();
        }
    }

}
